﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VCodeEditor.Document;

namespace VCodeEditor.FoldStrategies
{
	/// <summary>
	/// Fortran折叠策略
	/// </summary>
	public class FortranFoldStrategy : IFoldingStrategy
	{
		/// <summary>
		/// 生成代码折叠
		/// </summary>
		/// <param name="document">当前文档</param>
		/// <param name="fileName">文档名</param>
		/// <param name="parseInformation">Extra parse information, not used in this sample.</param>
		/// <returns>A list of FoldMarkers.</returns>
		public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
		{
			List<FoldMarker> list = new List<FoldMarker>();
			// Stack<FuncName> funName = new Stack<FuncName>();//函数名称
			Stack<int> startLines = new Stack<int>();
			for (int i = 0; i < document.TotalNumberOfLines; i++)
			{
				// 当前行文本
				string text = document.GetText(document.GetLineSegment(i));
				if (text.Trim().StartsWith("program"))
				{
					startLines.Push(i);
				}
				if (text.Trim().StartsWith("end program"))
				{
					int start = startLines.Pop();
					list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i, 57, FoldType.Region, "..."));
				}
			}
			return list;
		}
	}
}
